<template>
    <div>
        <city-header></city-header>
        <city-search :cities="cities"></city-search>
        <city-list
          :hotCities="hotCities"
          :cities="cities"
          :letter="letter"
        >
        </city-list>
        <city-alphabet
          :cities="cities"
          @change="letterChange">
        </city-alphabet>
    </div>
</template>

<script>
import CityHeader from '@/pages/city/components/Header'
import CitySearch from '@/pages/city/components/Search'
import CityList from '@/pages/city/components/List'
import CityAlphabet from '@/pages/city/components/Alphabet'
import axios from 'axios'

export default {
  name: 'City',
  components: {
    CityHeader: CityHeader,
    CitySearch: CitySearch,
    CityList: CityList,
    CityAlphabet: CityAlphabet
  },
  data () {
    return {
      hotCities: [],
      cities: {},
      letter: ''
    }
  },
  methods: {
    // 获取ajax数据
    getCityInfo: function () {
      axios.get('/api/city.json')
        .then(this.getCityInfoSucc)
    },
    getCityInfoSucc: function (res) {
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.hotCities = data.hotCities
        this.cities = data.cities
      }
    },
    letterChange: function (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.city = this.$route.query.city
    this.getCityInfo()
  }
}
</script>

<style lang="stylus" scoped>

</style>
